import java.util.Random;

public class Lab_01 {
    public static void main(String[] args) {
        Random random = new Random();
        int correctCount = 0; // 正确答案计数

        System.out.println("50道100以内加减法口算题：");
        System.out.println("========================");

        for (int i = 1; i <= 50; i++) {
            int num1 = random.nextInt(100) + 1; // 1-100
            int num2 = random.nextInt(100) + 1;
            boolean isAddition = random.nextBoolean(); // 随机选择加法或减法

            int result;
            String operator;

            if (isAddition) {
                // 加法，确保和在100以内
                while (num1 + num2 > 100) {
                    num1 = random.nextInt(50) + 1;
                    num2 = random.nextInt(50) + 1;
                }
                result = num1 + num2;
                operator = "+";
            } else {
                // 减法，确保结果非负
                if (num1 < num2) {
                    int temp = num1;
                    num1 = num2;
                    num2 = temp;
                }
                result = num1 - num2;
                operator = "-";
            }

            System.out.printf("%2d. %2d %s %2d = %3d%n", i, num1, operator, num2, result);
            correctCount++;
        }

        System.out.println("========================");
        System.out.println("完成！共生成 " + correctCount + " 道题目。");
    }
}